<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="/jsp/common/common.jsp" %>
</head>
<body>

<div class="tableMainWarp">
  <div class="top-div"><em></em><span>&nbsp;>&nbsp;系统监控&nbsp;>&nbsp;SQL Excute</span></div>
  <div>
    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="search-table">
      <tr><td valign="middle">Database :<select id="database"></select></td></tr>
      <tr>
        <td valign="middle">
        	SQL TEXT :<textarea id="sqlText" rows="4" cols="140"></textarea>
        </td>
        <td style="float: right;">
        	<font color="red">Dangerous Operation</font> <br> <font color="red">Keep your TWO eyes open</font>
	        <button class="btn-table" id="searchButton">Excute</button>
        </td>
      </tr>
    </table>
  </div>
  <div class="tablelist">
    <div class="tabcon" id="middleCon"  style="overflow: auto;"></div>
    <div id="paginationDiv"  class="page clearfix"></div>
  </div>
</div>


<script type="text/javascript">
$(document).ready(function(){
	
	var bodyHt=document.documentElement.clientHeight;
	var tableDivHeight = bodyHt-160;	
	$('#middleCon').height(tableDivHeight);

	getPageData();
	
	blindPageElement();
	
});

function getPageData(){
 	var url = '<%=basePath%>/webframework/sqlExcute/getPageData.do';
	$.ajax({  
        url:url,  
        type:'post',  
        dataType:'json',  
        success:function(data,textStatus,jqXHR){  
        	$(data).each(function(index,entry){
        		
        		var optionObj = $('<option></option>').attr('value',entry.value).append(entry.value);
        		$('#database').append(optionObj);
        	});
        },  
        error:function(XMLHttpRequest,textStatus,errorThrown){  
        }                     
    });
	
}

function blindPageElement(){

	$('#searchButton').on('click',function(){
		var param = new Object();
		param.sql = $('#sqlText').val();
		param.database = $('#database').val();
		getTableData(param);
	});
}

function getTableData(param){
 	
	var url = '<%=basePath%>/webframework/sqlExcute/excuteSql.do?method=1';
	
	$('#middleCon').tablegrid({
		url: url,
/* 		columns:[	
		   	        {field:'threadId',title:'ID',width:3},
		   	        {field:'threadName',title:'名称',width:10},
		   	        {field:'threadState',title:'状态',width:9},
		   	     	{field:'cpuTime',title:'CPU',width:4},
		   	        {field:'blockedCount',title:'阻塞计数',width:5},
		   	        {field:'blockedTime',title:'阻塞时间',width:5},
		   	        {field:'waitedCount',title:'等待计数',width:5},
		   	        {field:'waitedTime',title:'等待时间',width:5},
		   	        {field:'stackTraceElementList',title:'堆栈信息',width:54,formatter:contentFormatter}
			    ], */
	    isPagination:false,
	    resizeColumns : false,
	    param:param,
	    tableClass : 'table-form',
	    widthType : 'absolute',
	    beforeLoadFunction : function(data,options){
	    	
	    	var entry = data.tableData[0];
	    	
	    	var columns = new Array();
	    	$.each(entry,function(key,value){
	    		var obj = new Object();
	    		
	    		obj.field = key;
	    		obj.title = key;
	    		
	    		columns.push(obj);
	    	});
	    	
	    	options.columns = columns;
	    	return options;
	    }
	});
}

</script>
</body>
</html>